package top.xia17.plugins.fast.user.dao.entity;

import top.xia17.plugins.fast.common.database.jpa.extension.BaseUserTimeEntity;
import top.xia17.plugins.fast.common.database.jpa.extension.JpaEntity;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import top.xia17.plugins.fast.user.model.enums.MenuType;

import jakarta.persistence.*;
import java.util.Objects;

/**
 * 菜单实体
 * @author xia17
 * @since 2021/7/29 10:18
 */
@Getter
@Setter
@NoArgsConstructor
@Accessors(chain = true)
@Entity
@Table(name = "sys_menu")
public class Menu extends BaseUserTimeEntity implements JpaEntity<Long> {

    /** ID */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    /** 菜单标题 */
    private String title;

    /** 菜单组件名称 */
    private String componentName;

    /** 排序 */
    private Integer sort;

    /** 组件路径 */
    private String component;

    /** 路由地址 */
    private String path;

    /**
     * 菜单类型
     */
    @Enumerated(EnumType.STRING)
    private MenuType type;

    /** 权限标识 */
    private String permission;

    /** 菜单图标 */
    private String icon;

    /** 缓存 */
    private Boolean cache;

    /**
     * 是否隐藏
     */
    private Boolean hidden;

    /**
     * 父ID
     */
    private Long pid;

    /** 子节点数量 */
    private Integer subCount;

    /**
     * 是否外链菜单
     */
    private Boolean externalLink;

    /**
     * 是否移动端
     */
    private Boolean mobile;

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        Menu menu = (Menu) o;
        return Objects.equals(id, menu.id);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }
}
